<?php

/**
 * 敏感词后台管理
 * @copyright (c) 2013, Alvin
 * 
 */
class BadwordAction extends AdminAction {

    protected $model;

    public function _initialize() {
        parent::_initialize();
        $this->model = M('Badword');
    }

    public function edit() {
        if (IS_POST) {
            if (!$_POST['value']) {
                $this->error('参数填写不完整');
            }
            if ($_POST['id']) {
                $res = $this->model->save($_POST);
            } else {
                $res = $this->model->add($_POST);
            }

            $cacheID = 'badwords';
            F($cacheID);
            if ($res) {
                $this->success('操作成功', U('Badword/index'));
            } else {
                $this->success('操作失败');
            }
        } else {
            $id   = (int) $this->_get("id");
            $data = $this->model->find($id);
            $this->assign('data', $data);
            $this->display();
        }
    }

    public function delete() {
        $id      = (int) $this->_get("id");
        $cacheID = 'badwords';
        F($cacheID);
        if ($this->model->delete($id)) {
            $this->success("删除成功！");
        } else {
            $this->error("删除失败！");
        }
    }

}

?>
